<template>
  <div style="overflow-y: hidden">
    <div style="position: relative; height: calc(100vh - 200px); padding: 16px; overflow-y: hidden; background: #fff">
      <iframe id="reportFrame" :src="templateUrl" width="100%" height="100%" frameborder="0" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { deleteReportRecord } from "@/api/report";
import { onMounted, reactive, toRefs, ref, computed, nextTick } from "vue";
import { PxMessage, PxMessageBox } from "px-ui";
import { useRouter, useRoute } from "vue-router";
import { useNav } from "@/layout/hooks/useNav";
import dayjs from "dayjs";

defineOptions({
  name: "SYSTEM_BASE_INDICATOR_VERFIY"
});

const { username } = useNav();
const router = useRouter();
const route = useRoute();

const templateUrl = ref();
const submitAction = () => {
  document.getElementById("reportFrame").contentWindow.postMessage("_g().verifyAndWriteReport()", "*");
};
// importExcel_Clean清空导入
// importExcel_Append 增量导入
// importExcel_Cover 覆盖导入
const importAction = () => {
  document.getElementById("reportFrame").contentWindow.postMessage("_g().importExcel_Cover()", "*");
};
const exportAction = () => {
  document.getElementById("reportFrame").contentWindow.postMessage("_g().exportReportToExcel('simple')", "*");
};

const printAction = () => {
  // document.getElementById('reportFrame').contentWindow.contentPane.noClientPrint(true, true)();
  // let config = JSON.stringify({
  //   printUrl: `${VITE_FANRUAN_BASE_URL}/webroot/decision/view/report`,
  //   printType: 0, // 1
  //   isPopUp: true,
  //   pageType: 0,
  //   data: {
  //     reportlets:[{reportlet: `${decodeURIComponent(decodeURIComponent(route.query.template))}`, cmd: 'save_w_content', op: 'write', singleCode: route.query.singleCode}]
  //   }
  // })
  // // console.log('config:' + JSON.stringify(config));
  // // let config = JSON.stringify({ url: templateUrl.value, isPopUp: true });
  // //doURLPrint doURLPDFPrint
  // document.getElementById("reportFrame").contentWindow.postMessage(`FR.doURLPrint(${config})`, "*");
  document.getElementById("reportFrame").contentWindow.postMessage(`_g().noClientPrint(true,true)`, "*");
};
const { VITE_FANRUAN_BASE_URL } = import.meta.env;
const getUrl = () => {
  let tpName = encodeURIComponent(encodeURIComponent("指标验证.cpt"));
  let baseUrl = `${VITE_FANRUAN_BASE_URL}/webroot/decision/view/report?viewlet=${tpName}&user=${username.value}&ifpHost=${window.location.protocol}//${window.location.hostname}&op=write&facCode=${localStorage.getItem("facCode") || ""}`;
  templateUrl.value = baseUrl;
};
onMounted(() => {
  getUrl();
  window.addEventListener("message", function (event) {
    console.log(event);
    let o = `${VITE_FANRUAN_BASE_URL}`;
    if (event.origin !== o) return;
    let jumpUrl = JSON.parse(event.data)?.jumpUrl;
    if (jumpUrl) {
      window.open(jumpUrl, "_blank");
    }
  });
});

const searchAction = () => {
  getUrl();
};
</script>
<style scoped lang="scss">
.template-content {
  width: 100%;
  background-color: #fff;
}

.custom-form-ui {
  height: 38px;

  .px-form-item {
    margin-bottom: 0;
  }
}

.op-btns {
  display: flex;
  padding: 16px;
  margin: 5px 0;
  background-color: #fff;
  box-shadow: 0 0 10px 0 rgb(0 0 0 / 10%);

  .left {
    flex: 1;
    text-align: left;
  }

  .center {
    flex: 1;
    text-align: center;
  }

  .right {
    flex: 1;
    text-align: right;
  }
}

.footer-btns {
  text-align: right;
}
</style>
